package com.eva.learn.concurrent.thinkInJava;

/**
 * 自管理Runnable
 * (构造方法中调用start()事非常危险的，可能会变得很有问题，例如继承了该类的子方类，任务可能在构造器结束前开始运行，这种结果并不是设计预期的)
 * 
 * @author Evain.C
 *
 */
public class SelfManaged implements Runnable {
	private int countDown = 5;
	private Thread t = new Thread(this);

	public SelfManaged() {
		t.start();
	}

	public String toString() {
		return Thread.currentThread().getName() + "(" + countDown + "), ";
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		for (int i = 0; i < 5; i++) {
			new SelfManaged();
		}
	}
}
